package com.qzxy.premiumhotelsystem.controller.admin;

import com.qzxy.premiumhotelsystem.common.result.PageResult;
import com.qzxy.premiumhotelsystem.common.result.Result;
import com.qzxy.premiumhotelsystem.common.result.ResultCodeEnum;
import com.qzxy.premiumhotelsystem.domain.dto.RoomStockPageDTO;
import com.qzxy.premiumhotelsystem.domain.dto.RoomTypesDTO;
import com.qzxy.premiumhotelsystem.domain.entity.RoomTypes;
import com.qzxy.premiumhotelsystem.service.RoomTypesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: RoomTypesController
 * Package: com.qzxy.premiumhotelsystem.controller
 * Description:
 *
 * @Author Qwh
 * @Create 2024/9/12 16:04
 * @Version 1.0
 */

@RestController
@RequestMapping("/admin/roomTypes")
@Tag(name = "管理端房间类型",description = "管理端房间类型相关接口")
public class RoomTypesController {


    @Resource
    private RoomTypesService roomTypesService;



    @Operation(summary = "新增房间类型")
    @PostMapping("/add")
    public Result addRoom(@RequestBody @Validated RoomTypesDTO roomTypesDTO) {

        Result result = roomTypesService.addRoomTypes(roomTypesDTO);
        return result;
    }


    /**
     * 房间的类型查询
     *
     * @return
     */
    @Operation(summary = "房间类型查询")
    @GetMapping("/list")
    public Result list (){

        List<RoomTypes> list = roomTypesService.list();
        return Result.ok(list);

    }

    /**
     * 修改房间的类型
     * @param roomTypes
     * @return
     */
    @Operation(summary = "修改房间类型",description = "根据roomTypeId修改房间类型")
    @PutMapping("/update")
    public Result updateRoom(@RequestBody @Validated RoomTypes roomTypes){
        boolean updated = roomTypesService.updateById(roomTypes);
        if (!updated){
            return Result.build("更新失败,roomTypeId不存在", ResultCodeEnum.SERVER_ERROR);
        }
        return  Result.ok("房间类型修改成功");
    }

    /**
     * 根据roomTypeId删除房间类型
     * @param roomTypeId
     * @return
     */
    @Operation(summary = "删除房间类型",description = "根据roomTypeId删除房间类型")
    @DeleteMapping("/{roomTypeId}")
    public Result deleteRooms(@PathVariable Integer roomTypeId){
        boolean removed = roomTypesService.removeById(roomTypeId);
        if (!removed) {
            return Result.build("删除失败，房间类型不存在",ResultCodeEnum.SERVER_ERROR);
        }
        return Result.ok("删除房间类型成功");
    }

    @Operation(summary = "房间类型库存分页查询")
    @GetMapping("/queryStock")
    public Result<PageResult> queryRoomStock(@ParameterObject @Validated RoomStockPageDTO roomStockPageDTO) {

        Result<PageResult> result = roomTypesService.queryRoomStock(roomStockPageDTO);
        return result;

    }

    @Operation(summary = "统计各个房间类型的不同状态的数量")
    @GetMapping("/count")
    public Result count() {

        Result result = roomTypesService.countRooms();
        return result;

    }
}
